﻿// =================================================================== 
// 项目说明
//====================================================================
// lsc @Copy Right 2019
// 文件： NetworkOrderRejectDicRepository.cs
// 项目名称：斑马车务
// 创建时间：2019/1/23
// 负责人：lsc
// ===================================================================
using System;
using System.Text;
using System.Collections.Generic;
using CGT.Infrastructure.Entity;
using Dapper.Extensions;
using CGT.Infrastructure.Dto;
using Dapper;
using System.Linq;

namespace CGT.Infrastructure.Repository
{
	/// <summary>
	/// 仓储层
	/// </summary>	
	public class NetworkOrderRejectDicRepository:BaseRepository<NetworkOrderRejectDic>
	{		
    
        #region 构造

        public NetworkOrderRejectDicRepository() : base(){}

        public NetworkOrderRejectDicRepository(string connectionString) : base(connectionString){}

        public NetworkOrderRejectDicRepository(DatabaseContext dbContext) : base(dbContext){}

        #endregion

        /// <summary>
        /// 分页查询
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public Page<NetworkOrderRejectDicDto> GetPages(long pageIndex, long pageSize,int masterBizTypeId, int bizTypeId)
        {
            string sql = "SELECT r.*,t.BizTypeName FROM NetworkOrderRejectDic r with(nolock) inner join BizType t with(nolock) on r.BizTypeID = t.BizTypeID where t.IsActive = 1";
            if (masterBizTypeId>0)
            {
                sql += " and t.MasterBizTypeID=@MasterBizTypeID";
            }
            if (bizTypeId > 0)
            {
                sql += " and t.BizTypeID=@BizTypeID";
            }
            return dbContext.Connection.Page<NetworkOrderRejectDicDto>(pageIndex, pageSize, sql, new { MasterBizTypeID = masterBizTypeId, BizTypeID = bizTypeId });
        }

        /// <summary>
        /// 获取单数据信息
        /// </summary>
        /// <param name="dicId"></param>
        /// <returns></returns>
        public NetworkOrderRejectDicInterfaceDto GetInfoById(int dicId)
        {
            string sql = "SELECT r.*,t.MasterBizTypeID FROM NetworkOrderRejectDic r with(nolock) inner join BizType t with(nolock) on r.BizTypeID = t.BizTypeID where t.IsActive = 1 and r.DicId=@DicId";
            return dbContext.Connection.QueryFirst<NetworkOrderRejectDicInterfaceDto>(sql, new { DicId = dicId });
        }

        /// <summary>
        /// 获取单数据信息
        /// </summary>
        /// <param name="dicId"></param>
        /// <returns></returns>
        public List<NetworkOrderRejectDic> GetListByBizId(int bizId)
        {
            string sql = "SELECT * FROM NetworkOrderRejectDic with(nolock) where BizTypeId=@BizTypeId";
            return Query(sql, new { BizTypeId = bizId });
        }
    }
}